package com.mapaoer.user.service.impl;



import com.mapaoer.user.dao.UserRepository;
import com.mapaoer.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * 用户详情服务实现类
 * 简化版实现，移除了Spring Security依赖
 */
@Service
public class UserDetailsServiceImpl {

    @Autowired
    private UserRepository userRepository;

    /**
     * 根据用户名查找用户
     * @param username 用户名
     * @return 用户信息
     */
    public User findUserByUsername(String username) {
        Optional<User> optionalUser = userRepository.findByUsername(username);
        return optionalUser.orElse(null);
    }

    /**
     * 检查用户是否存在且状态正常
     * @param username 用户名
     * @return 是否有效
     */
    public boolean isValidUser(String username) {
        User user = findUserByUsername(username);
        return user != null && user.getStatus() == User.AccountStatus.ACTIVE;
    }
}